﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.MODEL.GoodsDelivery;

namespace ERPGoodsDelivery.MyControl
{
    public partial class userDeliveryHeap : UserControl
    {
        //属性
        /// <summary>
        /// 发货单号
        /// </summary>
        public int DeliveryId { get; set; }
        /// <summary>
        /// 堆内的账单集合
        /// </summary>
        public List<BillInfo> BillInfos { get; set; }
        /// <summary>
        /// 账单数量
        /// </summary>
        public int BillNum { get; set; }
        //参数
        public event DragEventHandler userDeliveryHeapDragDrop;
        public event DragEventHandler userDeliveryHeapDragEnter;
        public event DragEventHandler userDeliveryHeapDragOver;
        //public event DragEventHandler userDeliveryHeapDragLeave;
        public event EventHandler userClick;
        public userDeliveryHeap()
        {
            InitializeComponent();
        }

        private void userDeliveryHeap_Load(object sender, EventArgs e)
        {
            //设置控件的拖曳操作
            SetControlDrag(this);
        }

        public void controlDragDrop(object sender, DragEventArgs e)
        {
            if (userDeliveryHeapDragDrop != null)
            {
                //执行拖曳操作
                userDeliveryHeap heap = GetHeap(sender);
                userDeliveryHeapDragDrop(heap, e);
            }
        }
        public void controlDragEnter(object sender, DragEventArgs e)
        {
            if (userDeliveryHeapDragEnter != null)
            {
                userDeliveryHeap heap = GetHeap(sender);
                userDeliveryHeapDragEnter(heap, e);
            }
        }
        public void controlDragOver(object sender, DragEventArgs e)
        {
            if (userDeliveryHeapDragOver != null)
            {
                userDeliveryHeap heap = GetHeap(sender);
                userDeliveryHeapDragOver(heap, e);
            }
        }
        public void controlDragLeave(object sender, EventArgs e)
        {
            this.BorderStyle = BorderStyle.FixedSingle;
        }
        public void controlClick(object sender, EventArgs e)
        {
            if (userClick != null)
            {
                userDeliveryHeap heap = GetHeap(sender);
                userClick(heap, e);
            }
        }
        public void controlMouseEnter(object sender, EventArgs e)
        {
            this.BorderStyle = BorderStyle.Fixed3D;
        }
        public void controlMouseLeave(object sender, EventArgs e)
        {
            this.BorderStyle = BorderStyle.FixedSingle;
        }


        //---------------------------------------------------
        //----------------公共方法
        #region 设置用户控件的拖曳操作
        /// <summary>
        /// 设置用户控件的拖曳操作
        /// </summary>
        /// <param name="c"></param>
        public void SetControlDrag(Control c)
        {
            c.DragDrop += new DragEventHandler(controlDragDrop);
            c.DragEnter += new DragEventHandler(controlDragEnter);
            c.DragOver += new DragEventHandler(controlDragOver);
            c.DragLeave += new EventHandler(controlDragLeave);
            c.Click += new EventHandler(controlClick);
            c.MouseEnter += new EventHandler(controlMouseEnter);
            c.MouseLeave += new EventHandler(controlMouseLeave);
            c.AllowDrop = true;

            if (c.Controls != null && c.Controls.Count > 0)
            {
                foreach (Control subC in c.Controls)
                {
                    SetControlDrag(subC);
                }
            }
        }
        #endregion

        #region 获取最外层控件
        /// <summary>
        /// 获取最外层控件
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        public userDeliveryHeap GetHeap(object sender)
        {
            userDeliveryHeap heap = sender as userDeliveryHeap;
            if (heap != null)
                return heap;
            else
            {
                Control c = sender as Control;
                Control pareObj = c.Parent;
                return GetHeap(pareObj);
            }
        }
        #endregion

        #region 设置背景色
        /// <summary>
        /// 设置背景色
        /// </summary>
        public void SetBackColor()
        {
            this.BackColor = Color.Empty;
        }
        #endregion

        #region 设置送货单Id
        /// <summary>
        /// 设置送货单Id
        /// </summary>
        public void SetDeliveryId()
        {
            this.lblDeliveryId.Text = DeliveryId.ToString();
        }
        #endregion

        #region 设置账单数量
        /// <summary>
        /// 设置账单数量
        /// </summary>
        public void SetBillNum()
        {
            this.lblBillNum.Text = BillNum.ToString();
        }
        #endregion
    }
}
